package com.realife.ysuper.controller;

import com.realife.common.utils.R;
import com.realife.ysuper.entity.ApplicationPrivilegeEntity;
import com.realife.ysuper.service.ApplicationPrivilegeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;



/**
 * 服务中间表，记录服务id以及服务能访问的目标服务的id
 *
 * @author Albert
 * @email 15962463559@163.com
 * @date 2020-06-05 10:04:16
 */
@Slf4j
@RestController
@RequestMapping("/ysuper/applicationprivilege")
public class ApplicationPrivilegeController {

    @Autowired
    private ApplicationPrivilegeService applicationPrivilegeService;



    /**
     * 信息
     */
    @RequestMapping("/info/{serviceId}")
    //@RequiresPermissions("ysuper:applicationprivilege:info")
    public R info(@PathVariable("serviceId") Integer serviceId){
		ApplicationPrivilegeEntity applicationPrivilege = applicationPrivilegeService.getById(serviceId);

        return R.ok().put("applicationPrivilege", applicationPrivilege);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ysuper:applicationprivilege:save")
    public R save(@RequestBody ApplicationPrivilegeEntity applicationPrivilege){
		applicationPrivilegeService.save(applicationPrivilege);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ysuper:applicationprivilege:update")
    public R update(@RequestBody ApplicationPrivilegeEntity applicationPrivilege){
		applicationPrivilegeService.updateById(applicationPrivilege);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ysuper:applicationprivilege:delete")
    public R delete(@RequestBody Integer[] serviceIds){
		applicationPrivilegeService.removeByIds(Arrays.asList(serviceIds));

        return R.ok();
    }

}
